
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import java.util.Calendar;
import java.text.SimpleDateFormat;

public class frame extends javax.swing.JFrame {

    public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
    String output = ""; //for the last action performed log on screen 
    Node node = new Node(); //node size determined by array length
    LinkedStack stack = new LinkedStack(); //create a new linked stack to store the nodes

    public frame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        actionPanel = new javax.swing.JPanel();
        BUttonPanel = new javax.swing.JPanel();
        checkForEmptyStackBtn = new javax.swing.JButton();
        checkForFullStackBtn = new javax.swing.JButton();
        insertDataAtTopOfStack = new javax.swing.JButton();
        removeDataFromTopOfStack = new javax.swing.JButton();
        dataCurrentlyAtTopOfStack = new javax.swing.JButton();
        currentNumberOfItemsInStackButton = new javax.swing.JButton();
        clearStackButton = new javax.swing.JButton();
        searchButton = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        descriptionPanel = new javax.swing.JPanel();
        description1Lbl = new javax.swing.JLabel();
        description2Lbl = new javax.swing.JLabel();
        description3Lbl = new javax.swing.JLabel();
        description4Lbl = new javax.swing.JLabel();
        description5Lbl = new javax.swing.JLabel();
        description6Lbl = new javax.swing.JLabel();
        description7Lbl = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        displayPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        displayArea = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(255, 153, 51));
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        actionPanel.setBackground(new java.awt.Color(204, 255, 255));
        actionPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(51, 51, 255)));

        BUttonPanel.setBackground(new java.awt.Color(204, 255, 204));
        BUttonPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(204, 0, 0)));
        BUttonPanel.setFont(new java.awt.Font("Tahoma", 1, 11));

        checkForEmptyStackBtn.setText("1");
        checkForEmptyStackBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkForEmptyStackBtnActionPerformed(evt);
            }
        });

        checkForFullStackBtn.setText("2");
        checkForFullStackBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkForFullStackBtnActionPerformed(evt);
            }
        });

        insertDataAtTopOfStack.setText("3");
        insertDataAtTopOfStack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insertDataAtTopOfStackActionPerformed(evt);
            }
        });

        removeDataFromTopOfStack.setText("4");
        removeDataFromTopOfStack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeDataFromTopOfStackActionPerformed(evt);
            }
        });

        dataCurrentlyAtTopOfStack.setText("5");
        dataCurrentlyAtTopOfStack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dataCurrentlyAtTopOfStackActionPerformed(evt);
            }
        });

        currentNumberOfItemsInStackButton.setText("6");
        currentNumberOfItemsInStackButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                currentNumberOfItemsInStackButtonActionPerformed(evt);
            }
        });

        clearStackButton.setText("7");
        clearStackButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearStackButtonActionPerformed(evt);
            }
        });

        searchButton.setText("8");
        searchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchButtonActionPerformed(evt);
            }
        });

        jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/asterisk_red.png"))); // NOI18N
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout BUttonPanelLayout = new javax.swing.GroupLayout(BUttonPanel);
        BUttonPanel.setLayout(BUttonPanelLayout);
        BUttonPanelLayout.setHorizontalGroup(
            BUttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 189, Short.MAX_VALUE)
            .addGroup(BUttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(BUttonPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(BUttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(checkForEmptyStackBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(insertDataAtTopOfStack, 0, 0, Short.MAX_VALUE)
                        .addComponent(checkForFullStackBtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(BUttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(BUttonPanelLayout.createSequentialGroup()
                            .addGroup(BUttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(dataCurrentlyAtTopOfStack)
                                .addComponent(removeDataFromTopOfStack))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(BUttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(searchButton)
                                .addComponent(clearStackButton)))
                        .addGroup(BUttonPanelLayout.createSequentialGroup()
                            .addComponent(currentNumberOfItemsInStackButton)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jButton9, 0, 0, Short.MAX_VALUE)))
                    .addContainerGap(46, Short.MAX_VALUE)))
        );

        BUttonPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {dataCurrentlyAtTopOfStack, removeDataFromTopOfStack});

        BUttonPanelLayout.setVerticalGroup(
            BUttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 132, Short.MAX_VALUE)
            .addGroup(BUttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(BUttonPanelLayout.createSequentialGroup()
                    .addGap(9, 9, 9)
                    .addGroup(BUttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(checkForEmptyStackBtn)
                        .addComponent(removeDataFromTopOfStack)
                        .addComponent(clearStackButton))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(BUttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(checkForFullStackBtn)
                        .addComponent(dataCurrentlyAtTopOfStack)
                        .addComponent(searchButton))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(BUttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(insertDataAtTopOfStack)
                        .addComponent(currentNumberOfItemsInStackButton)
                        .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(42, Short.MAX_VALUE)))
        );

        BUttonPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {checkForEmptyStackBtn, checkForFullStackBtn, dataCurrentlyAtTopOfStack, insertDataAtTopOfStack, removeDataFromTopOfStack});

        descriptionPanel.setBackground(new java.awt.Color(204, 255, 204));
        descriptionPanel.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(204, 0, 0)));
        descriptionPanel.setAutoscrolls(true);
        descriptionPanel.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
        descriptionPanel.setFont(new java.awt.Font("Tahoma", 1, 11));

        description1Lbl.setText("1.) Check For Empty Stack");

        description2Lbl.setText("2.) Check For Full Stack");

        description3Lbl.setText("3.) Insert DataAt Top Of Stack");

        description4Lbl.setText("4.) Remove Data From Top Of Stack ");

        description5Lbl.setText("5.) Data Currently At Top Of Stack");

        description6Lbl.setText("6.) Current No. Of Items In Stack");

        description7Lbl.setText("7.) Clear All Data From Stack");

        jLabel1.setText("8.) Search Stack");

        javax.swing.GroupLayout descriptionPanelLayout = new javax.swing.GroupLayout(descriptionPanel);
        descriptionPanel.setLayout(descriptionPanelLayout);
        descriptionPanelLayout.setHorizontalGroup(
            descriptionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(descriptionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(descriptionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(description4Lbl)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, descriptionPanelLayout.createSequentialGroup()
                        .addGroup(descriptionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(descriptionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(descriptionPanelLayout.createSequentialGroup()
                                    .addComponent(description2Lbl, javax.swing.GroupLayout.DEFAULT_SIZE, 345, Short.MAX_VALUE)
                                    .addGap(39, 39, 39))
                                .addGroup(descriptionPanelLayout.createSequentialGroup()
                                    .addComponent(description3Lbl)
                                    .addGap(33, 33, 33)))
                            .addGroup(descriptionPanelLayout.createSequentialGroup()
                                .addComponent(description1Lbl)
                                .addGap(54, 54, 54)))
                        .addGroup(descriptionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(description5Lbl)
                            .addComponent(description7Lbl)
                            .addComponent(description6Lbl)
                            .addComponent(jLabel1))
                        .addGap(48, 48, 48)))
                .addContainerGap())
        );
        descriptionPanelLayout.setVerticalGroup(
            descriptionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(descriptionPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(descriptionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(description1Lbl)
                    .addComponent(description5Lbl))
                .addGap(9, 9, 9)
                .addGroup(descriptionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(description2Lbl)
                    .addComponent(description6Lbl))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(descriptionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(description3Lbl)
                    .addComponent(description7Lbl))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(descriptionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(description4Lbl)
                    .addComponent(jLabel1)))
        );

        javax.swing.GroupLayout actionPanelLayout = new javax.swing.GroupLayout(actionPanel);
        actionPanel.setLayout(actionPanelLayout);
        actionPanelLayout.setHorizontalGroup(
            actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(actionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(BUttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(descriptionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        actionPanelLayout.setVerticalGroup(
            actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(actionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(actionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(descriptionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(BUttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        displayArea.setBackground(new java.awt.Color(255, 204, 204));
        displayArea.setColumns(20);
        displayArea.setEditable(false);
        displayArea.setFont(new java.awt.Font("Monospaced", 1, 13)); // NOI18N
        displayArea.setRows(5);
        jScrollPane1.setViewportView(displayArea);

        javax.swing.GroupLayout displayPanelLayout = new javax.swing.GroupLayout(displayPanel);
        displayPanel.setLayout(displayPanelLayout);
        displayPanelLayout.setHorizontalGroup(
            displayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 842, Short.MAX_VALUE)
        );
        displayPanelLayout.setVerticalGroup(
            displayPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(actionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 842, Short.MAX_VALUE)
                    .addComponent(displayPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(displayPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(actionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

//int currentTop = nodeSizeArray[node.getnodePointer()]; //returns current value at nodepointer
private void checkForEmptyStackBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkForEmptyStackBtnActionPerformed
    if (stack.isEmpty() == true) {
        JOptionPane.showMessageDialog(null, "The Linked stack is empty!", now(), JOptionPane.INFORMATION_MESSAGE);
        displayArea.setText(now() + " Last Action: checked if node was empty, it was empty!");
        output += ("\n" + now() + " Last Action: checked if node was empty, it was empty!");
    } else if (stack.isEmpty() == false) {
            
                JOptionPane.showMessageDialog(null, "The Linked Stack is not empty!, Stack contains: "+stack.size()+" Items", now(), JOptionPane.INFORMATION_MESSAGE);
            
        displayArea.setText(now() + " Last Action: checked if Stack was empty, it was NOT empty!");
        output += ("\n" + now() + " Last Action: checked if stack was empty, it was NOT empty! stack contains: " + stack.size()+" items");

    }

    displayArea.setText(output);



}//GEN-LAST:event_checkForEmptyStackBtnActionPerformed

private void checkForFullStackBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkForFullStackBtnActionPerformed
    //stack / node cannot be full is a dynamic structure
}//GEN-LAST:event_checkForFullStackBtnActionPerformed

private void insertDataAtTopOfStackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_insertDataAtTopOfStackActionPerformed
try{
    String inputStr=JOptionPane.showInputDialog("Enter The String To Insert At Top Of Stack");
    node.setElement(inputStr);  // insert the data on the node
    stack.push(node);           // push that node onto the stack
    displayArea.setText(now() + " Last Action: Inserted Data At Top Of Stack, Inserted"+inputStr);
        output += ("\n" + now() + " Last Action: Inserted String Value on Stack,  Inserted: " + inputStr);
        displayArea.setText(output);
}
catch(NumberFormatException nfe){
    JOptionPane.showMessageDialog(null,"Error, Something Went Wrong", "Please Enter a String!",JOptionPane.ERROR_MESSAGE);
}
}//GEN-LAST:event_insertDataAtTopOfStackActionPerformed

private void removeDataFromTopOfStackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeDataFromTopOfStackActionPerformed
    if(stack.isEmpty()==false){ 
    try {
        //displayArea.setText(now() + " Last Action: Removed Data At Top Of Stack, Removed" + node.getElement());
        output += ("\n" + now() + " Last Action: Removed String Value on Stack,  Removed: " + node.getElement());
        stack.pop();
        displayArea.setText(output);
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null,"Cannot pop off an already EMPTY stack!","Error, Something Went Wrong" ,JOptionPane.ERROR_MESSAGE);
        output += ("\n" + now() + " Last Action: Exception Caught: Cannot pop off an already EMPTY stack!" );
        displayArea.setText(output);
    }
    }
    else if(stack.isEmpty()==true){
        JOptionPane.showMessageDialog(null,"Cannot pop off an already EMPTY stack!","Error, Something Went Wrong" ,JOptionPane.ERROR_MESSAGE);
        output += ("\n" + now() + " Last Action: Exception Caught: Cannot pop off an already EMPTY stack!" );
        displayArea.setText(output);
    
    }

}//GEN-LAST:event_removeDataFromTopOfStackActionPerformed

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
// look at me editing things to make them up to date 18/10/11 16.43
    int exit = JOptionPane.showConfirmDialog(null, "Are you sure?");
    if (exit == JOptionPane.YES_OPTION) {
        try {
            System.exit(exit);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "An Exception Occured: " + e.getMessage());
        }
    }
    if (exit == JOptionPane.NO_OPTION) {
        JOptionPane.showMessageDialog(null, "Returning to Program!");
    }
    if (exit == JOptionPane.CANCEL_OPTION) {
        JOptionPane.showMessageDialog(null, "Returning to Program!");
    }
}//GEN-LAST:event_jButton9ActionPerformed

private void dataCurrentlyAtTopOfStackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dataCurrentlyAtTopOfStackActionPerformed
 if(stack.isEmpty()==false){
    try {
        displayArea.setText(now() + " Last Action: Checked Data At Top Of Stack, current data at top of stack is:" + node.getElement());
        output += ("\n" + now() + " Last Action: Checked Stack top,  current data at top of stack is: " + node.getElement());
        
        displayArea.setText(output);
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null,"Cannot get element at top of an already EMPTY stack!","Error, Something Went Wrong" ,JOptionPane.ERROR_MESSAGE);
        output += ("\n" + now() + " Last Action: Exception Caught: Cannot get data from top of an already EMPTY stack!" );
        displayArea.setText(output);
    }    
 }
 else if(stack.isEmpty()==true){
     JOptionPane.showMessageDialog(null,"Cannot get element at top of an already EMPTY stack!","Error, Something Went Wrong" ,JOptionPane.ERROR_MESSAGE);
        output += ("\n" + now() + " Last Action: Exception Caught: Cannot get data from top of an already EMPTY stack!" );
        displayArea.setText(output);
 }
}//GEN-LAST:event_dataCurrentlyAtTopOfStackActionPerformed

private void currentNumberOfItemsInStackButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_currentNumberOfItemsInStackButtonActionPerformed
 if(stack.isEmpty()==false){
    try {
        //displayArea.setText(now() + " Last Action: Checked size Of Stack, current stack size is:" +stack.size());
        output += ("\n" + now() + " Last Action: Checked size Of Stack, current stack size is:" +stack.size());
        
        displayArea.setText(output);
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null,"Cannot Check size Of Stack!","Error, Something Went Wrong" ,JOptionPane.ERROR_MESSAGE);
        output += ("\n" + now() + " Last Action: Exception Caught: Cannot Check size Of Stack! Stack Empty!" );
        displayArea.setText(output);
    }    
 }
 else if(stack.isEmpty()==true){
     JOptionPane.showMessageDialog(null,"Cannot Check size Of Stack! Stack Empty!","Error, Something Went Wrong" ,JOptionPane.ERROR_MESSAGE);
        output += ("\n" + now() + " Last Action: Exception Caught: Cannot Check size Of Stack! Stack Empty!" );
        displayArea.setText(output);
 }    
}//GEN-LAST:event_currentNumberOfItemsInStackButtonActionPerformed

private void clearStackButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearStackButtonActionPerformed
if(stack.isEmpty()==false){
    try {
        //displayArea.setText(now() + " Last Action: Checked size Of Stack, current stack size is:" +stack.size());
        output += ("\n" + now() + " Last Action: Emptied Stack!!");
        stack.clearStack();
        displayArea.setText(output);
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null,"Cannot Clear Already Empty Stack!","Error, Something Went Wrong" ,JOptionPane.ERROR_MESSAGE);
        output += ("\n" + now() + " Last Action: Exception Caught: Cannot Clear Already Empty Stack!" );
        displayArea.setText(output);
    }    
 }
 else if(stack.isEmpty()==true){
      JOptionPane.showMessageDialog(null,"Cannot Clear Already Empty Stack!","Error, Something Went Wrong" ,JOptionPane.ERROR_MESSAGE);
        output += ("\n" + now() + " Last Action: Exception Caught: Cannot Clear Already Empty Stack!" );
        displayArea.setText(output);
 }    
    
    
    
    

}//GEN-LAST:event_clearStackButtonActionPerformed

private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
   
    String elementToFind;
    if (stack.isEmpty() == false) {
        try {
            elementToFind = JOptionPane.showInputDialog(null, "Enter A Number To Search For: ");
            boolean result=false;
                try {
                    result = stack.search(elementToFind,stack.size(),stack);
                } catch (StackException ex) {
                    Logger.getLogger(frame.class.getName()).log(Level.SEVERE, null, ex);
                }
            if (result == true) {
                JOptionPane.showMessageDialog(null, "Element Found", "Element" + elementToFind + " Found In node", JOptionPane.INFORMATION_MESSAGE);
                output += ("\n" + now() + " Last Action: Searched for element: " + elementToFind + " In node, and found it. ");



            } //if found is still false so it means this element is not found
            else if (result == false) {
                JOptionPane.showMessageDialog(null, "Element NOT Found", "Element" + elementToFind + " NOT Found In Stack", JOptionPane.ERROR_MESSAGE);
                output += ("\n" + now() + " Last Action: Searched for element: " + elementToFind + " In Stack, FAIL...NOT found!");
            }
        } catch (NumberFormatException nfe) {
            JOptionPane.showMessageDialog(null, "Enter a Valid String to search for!", "YOU BROKE IT!", JOptionPane.ERROR_MESSAGE);
            output += ("\n" + now() + " Last Action: EXCEPTION!!you tried breaking my system by entering an invalid character");
        }
        displayArea.setText(output);
    } else if (stack.isEmpty() == true) {
        JOptionPane.showMessageDialog(null, "The Stack is Empty! ", "Cannot Search an already empty Stack", JOptionPane.ERROR_MESSAGE);
        output += ("\n" + now() + " Last Action: Tried Searching Stack. FAIL... Stack is Empty");
        displayArea.setText(output);
    }



}//GEN-LAST:event_searchButtonActionPerformed

    public static String now() {
        // method uses calendar class to get current date and time for status messages
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
        return sdf.format(cal.getTime());
// method used for timestamp
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frame().setVisible(true);
            }
        });
    }
//    public boolean searchnode (int item)
// {
// int x=nodePointer;
// while (x>=0)
// {
// if (item==element[x]){
// return true; 
//}else{
// x=x-1;
// }
// }
// return false;
// }
//    public boolean searchnode(int item) {
//        int pointer = node.getnodePointer();
//        //int element = node.getElement(pointer);
//        while (x >= 0) {
//            if (item == node.getElement()[x]) {
//                return true;
//            } 
//            else x=-1;
//        }
//        return false;
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel BUttonPanel;
    private javax.swing.JPanel actionPanel;
    private javax.swing.JButton checkForEmptyStackBtn;
    private javax.swing.JButton checkForFullStackBtn;
    private javax.swing.JButton clearStackButton;
    private javax.swing.JButton currentNumberOfItemsInStackButton;
    private javax.swing.JButton dataCurrentlyAtTopOfStack;
    private javax.swing.JLabel description1Lbl;
    private javax.swing.JLabel description2Lbl;
    private javax.swing.JLabel description3Lbl;
    private javax.swing.JLabel description4Lbl;
    private javax.swing.JLabel description5Lbl;
    private javax.swing.JLabel description6Lbl;
    private javax.swing.JLabel description7Lbl;
    private javax.swing.JPanel descriptionPanel;
    private javax.swing.JTextArea displayArea;
    private javax.swing.JPanel displayPanel;
    private javax.swing.JButton insertDataAtTopOfStack;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton removeDataFromTopOfStack;
    private javax.swing.JButton searchButton;
    // End of variables declaration//GEN-END:variables
}
